package com.huaxinkai.mobile.socket;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class SocketTest {

	public static void main(String[] args) throws UnknownHostException {
		//获取本机的inetAddress实例
		InetAddress address = InetAddress.getLocalHost();
		String local = address.getHostName();
		String hostAddress = address.getHostAddress();
		System.out.println("计算机名："+local);
		System.out.println("ip地址："+hostAddress);
		
		//根据机器名获取InetAddress实例
//		InetAddress ad2 = InetAddress.getByName("DESKTOP-G6HI5P2");
		InetAddress ad2 = InetAddress.getByName("192.168.0.100");
		System.out.println("计算机名2："+ad2.getHostName());
		System.out.println("ip地址2："+ad2.getHostAddress());
	}

}
